﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;

namespace imarks.BLL.Membership
{
    /// <summary>
    /// 角色管理服务
    /// </summary>
    public class RoleService
    {
        /// <summary>
        /// 创建角色
        /// </summary>
        /// <param name="roleName">角色名</param>
        public void CreateRole(string roleName)
        {
            Roles.CreateRole(roleName);
        }

        /// <summary>
        /// 将用户添加到角色
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="roleName">角色名</param>
        public void AddUserToRole(string userName, string roleName)
        {
            Roles.AddUserToRole(userName, roleName);
        }

        /// <summary>
        /// 指定用户是否属于指定角色
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="roleName">角色名</param>
        /// <returns></returns>
        public bool IsUserInRole(string userName,string roleName)
        {
            return Roles.IsUserInRole(userName, roleName);
        }

        /// <summary>
        /// 获取所有管理员账号
        /// </summary>
        /// <returns></returns>
        public string[] GetAllAdmin(string usernameToMatch)
        {
            return Roles.FindUsersInRole("Administrators", "%"+usernameToMatch+"%");
        }
    }
}
